package org.fall.mvc.handler;

import crowd.entity.Admin;
import crowd.entity.AdminExample;
import org.fall.service.api.AdminService;
import org.fall.util.CrowdUtil;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author XZ
 * @create 2021-11-28 10:49
 */
@Controller
public class TestHandler {

    @Autowired
    AdminService adminService;

    @ResponseBody
    @RequestMapping("/send/array/one.html")
    public String testAjax01(@RequestParam("array") Integer[] array){
        for(Integer num : array){
            System.out.println("num:"+num);
        }
        return "success";
    }

    //通过@RequestBody接收数组
    @ResponseBody
    @RequestMapping("/send/array/two.html")
    public String testAjax02(@RequestBody Integer[] array){
        System.out.println("=========="+array);
        for(Integer num : array){
            System.out.println("==========num:"+num);
        }
        return "success";
    }

    @RequestMapping("/test/ssm.html")
    public String testSSM(Model model, HttpServletRequest request) {
        boolean judgeRequest = CrowdUtil.judgeRequestType(request);
//        System.out.println("是json数据类型：："+judgeRequest);
        List<Admin> admins = adminService.getAll();
        model.addAttribute("admins", admins);
//        System.out.println("==========" + admins);
//        System.out.println(10/0);
//        String a = null;
//        System.out.println(a.length());
        return "redirect:/admin/to/login/page.html";
    }
}